unit PesquisaPortador;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, UFormPesquisa, DB, DBTables, StdCtrls, Grids, DBGrids, Buttons,
  ExtCtrls;

type
  TFPesquisaPortador = class(TFormPesquisa)
    Label1: TLabel;
    ENome: TEdit;
    procedure BtnConsultarClick(Sender: TObject);
    procedure BtnLimparClick(Sender: TObject);
    procedure BtnImprimirClick(Sender: TObject);
    procedure BtnSelecionarClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FPesquisaPortador: TFPesquisaPortador;

implementation

uses  RelatorioPortador, CadastroPortador, UFormRelatorio;

{$R *.dfm}

procedure TFPesquisaPortador.BtnConsultarClick(Sender: TObject);
begin
 QPesquisa.close;
 QPesquisa.SQL.Clear;
 QPesquisa.SQL.Add(' Select * from Portador ');
 QPesquisa.SQL.Add('Where (Port_Codigo = Port_Codigo)');
 if ENome.Text <> '' then
  begin
   QPesquisa.SQL.Add(' And (Port_Descricao Like :Desc)');
   QPesquisa.ParamByName('Desc').AsString:='%' + ENome.Text +'%' ;
  end;

 QPesquisa.open;

inherited;
end;

procedure TFPesquisaPortador.BtnLimparClick(Sender: TObject);
begin
  inherited;
 ENome.Text:='';

end;

procedure TFPesquisaPortador.BtnImprimirClick(Sender: TObject);
begin
  inherited;
 DSPesquisa.Enabled:=false;
 Application.CreateForm(TFRelatorioPortador, FRelatorioPortador);
 with FRelatorioPortador do
  begin
   QRLNomeRelatorio.Caption:='PORTADOR';
   QuickRep1.DataSet:=QPesquisa;
   QuickRep1.Prepare;
   QuickRep1.Preview;
   close;
  end;
 DSPesquisa.Enabled:=true;
end;

procedure TFPesquisaPortador.BtnSelecionarClick(Sender: TObject);
begin
  inherited;
 FCadastroPortador.QPortador.Close;
 FCadastroPortador.QPortador.Open;
 FCadastroPortador.QPortador.Locate('Port_Codigo',QPesquisa.fieldByname('Port_Codigo').AsString,[loCaseInsensitive]);
 Self.Close;
end;

procedure TFPesquisaPortador.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
 FCadastroPortador.Enabled:=true;
 FCadastroPortador.Show;
 FPesquisaPortador:=nil;
  inherited;
end;

end.
